package com.mdc;

//import java.util.ArrayList;
//import java.util.List;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.EventListener;

//@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{
    /*@Bean
    public ServletRegistrationBean myServlet(){
        *//*ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.setServlet(new MyServlet());*//*

        *//*List<String> urlMappings = new ArrayList<>();
        urlMappings.add("/a-servlet");//访问，可以添加多个
        regBean.setUrlMappings(urlMappings);*//*

        ServletRegistrationBean regBean =
                new ServletRegistrationBean(new MyServlet());
        regBean.addUrlMappings("/a");
        regBean.addUrlMappings("/a-servlet");
        regBean.setLoadOnStartup(1);
        return regBean;
    }*/

    @Bean
    public FilterRegistrationBean myFilter(){
        /*FilterRegistrationBean regBean = new FilterRegistrationBean();
        regBean.setFilter(new MyFilter());

        List<String> urlPatterns = new ArrayList<>();
        urlPatterns.add("/*");//拦截路径，可以添加多个
        regBean.setUrlPatterns(urlPatterns);*/

        FilterRegistrationBean regBean =
                new FilterRegistrationBean(new MyFilter());
        regBean.addUrlPatterns("/*");

        regBean.setOrder(1);
        return regBean;
    }

    @Bean
    public ServletListenerRegistrationBean<EventListener> myListener(){
        /*ServletListenerRegistrationBean<EventListener> regBean
                = new ServletListenerRegistrationBean<>();
        regBean.setListener(new MyListener());
		registrationBean.setOrder(1);*/
        ServletListenerRegistrationBean<EventListener> regBean =
                new ServletListenerRegistrationBean<>(new MyListener());
        return regBean;
    }
}
